"""
@Time    : 2025/7/22 9:52
@Author  : white.tie
@File    : response.py
@Desc    :  直接返回响应
"""
import json
from datetime import datetime
from typing import Union

import uvicorn
from fastapi import FastAPI
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from pydantic import BaseModel


class Item(BaseModel):
    title: str
    timestamp: datetime
    description: Union[str, None] = None


app = FastAPI()


@app.put("/items/{id}")
def update_item(id: str, item: Item):
    print(type(item))
    print(item)
    json_compatible_item_data = jsonable_encoder(item)
    return JSONResponse(content=json_compatible_item_data)


if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8010)
#     curl --location --request PUT '127.0.0.1:8010/items/ddd'  --header 'Content-Type: application/json'  --data '{"title":"test","timestamp":"1753149369"
